﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '分类名称', name: 'Name', width: "15%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: '排序', name: 'Sequence', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "13%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = []; 
            ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>编辑</a>");
            ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[0], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });

        $("#btnAdd").click(function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        });

        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };

        util.GiveUser = function (id) {
            var url = options.giveuserUrl + "/" + id;
    
            location.href = url;
        };

        util.Give = function (id) {
            var url = options.givemoduleUrl + "/" + id;
   
            location.href = url;
        };

        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");
                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);